﻿using Unity.Netcode;
using UnityEngine;

public class EnemyPoolHandler : MonoBehaviour
{
    [SerializeField]
    GameObject greenSlimePrefab,
        purpleSlimePrefab,
        birthIdentifier;
    NGOPool<Slime> gSlimePools, pSlimePools;
    NGOPool<Transform> birthIdentifierPools;

    private void Start()
    {
        var nm = NetworkManager.Singleton;
        //注册NetworkPrefabHandler

        gSlimePools = new(greenSlimePrefab, maxNum: 10);
        pSlimePools = new(purpleSlimePrefab, maxNum: 10);
        birthIdentifierPools = new(birthIdentifier, maxNum:10);
        nm.PrefabHandler.AddHandler(greenSlimePrefab, gSlimePools);
        nm.PrefabHandler.AddHandler(purpleSlimePrefab, pSlimePools);
        nm.PrefabHandler.AddHandler(birthIdentifier, birthIdentifierPools);
    }

    private void OnDestroy()
    {
        var nm = NetworkManager.Singleton;
        if(nm == null)
            return;
        nm.PrefabHandler.RemoveHandler(greenSlimePrefab);
        nm.PrefabHandler.RemoveHandler(purpleSlimePrefab);
        nm.PrefabHandler.RemoveHandler(birthIdentifier);
    }
}